class Solution {
public:
    vector<int> findAnagrams(string s, string p) {
        int m = s.size();
        int n = p.size();
        if(m < n) return {};
        
        vector<int> ans;
        vector<int> hash1(26),hash2(26);
        
        for(int i = 0;i < n;i++){
            hash1[s[i] - 'a']++;
            hash2[p[i] - 'a']++;
        }
        if(hash1 == hash2) ans.push_back(0);
        
        int l = 1,r = n;
        while(r < m){
            hash1[s[l-1] - 'a']--;
            hash1[s[r] - 'a']++;
            
            if(hash1 == hash2){
                ans.push_back(l);
            }
            
            l++;
            r++;
        }
        
        return ans;
        
    }
};

